package com.beta.inventory;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


public class SimpleSpot implements Spot {

	private Map<String, Integer> signals = Collections.synchronizedMap(new HashMap<String, Integer>());
	
	// dependencies
	private PullListener spotObserver;
	
	public void setSpotObserver(PullListener spotObserver) {
		this.spotObserver = spotObserver;
	}

	public void receiveSignal(String signal) {
		signals.put(signal, count(signal) + 1);
	}

	public Integer count(String signal) {
		if (signals.containsKey(signal))
		return signals.get(signal);
		
		return 0;
	}

	public Collection<String> signals() {
		return signals.keySet();
	}

	public void processSignal(String signal) {
		
		signals.put(signal, count(signal)-1);
		
		spotObserver.replenish(signal);
	}

}
